from PyQt5 import QtCore, QtGui, QtWidgets
import qt_shiyong_rc
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
import cv2
import sys

from _2xinxi_caiji import xinxi_caiji
from _3gengxin_renlian import gengxin_xinxi
from _4xuesheng_kaoqin import kaoqin
from _5xinxi_shuju_xianshi import shuju_xianshi

class MainWindow(QWidget):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(707, 641)
        MainWindow.setMinimumSize(QtCore.QSize(707, 641))
        MainWindow.setMaximumSize(QtCore.QSize(707, 641))
        MainWindow.setStyleSheet("background-image: url(:/新前缀/好看的图片.jpg);")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.zhu_btn_kaoqin = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_kaoqin.setGeometry(QtCore.QRect(360, 540, 151, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_kaoqin.setFont(font)
        self.zhu_btn_kaoqin.setStyleSheet("image: url(:/新前缀/考勤.png);")
        self.zhu_btn_kaoqin.setText("")
        self.zhu_btn_kaoqin.setObjectName("zhu_btn_kaoqin")
        self.biaoti = QtWidgets.QLabel(self.centralwidget)
        self.biaoti.setGeometry(QtCore.QRect(40, 0, 641, 91))
        font = QtGui.QFont()
        font.setFamily("黑体")
        font.setPointSize(36)
        self.biaoti.setFont(font)
        self.biaoti.setObjectName("biaoti")
        self.zhu_btn_caiji = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_caiji.setGeometry(QtCore.QRect(10, 540, 151, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_caiji.setFont(font)
        self.zhu_btn_caiji.setStyleSheet("image: url(:/新前缀/数据采集.png);")
        self.zhu_btn_caiji.setText("")
        self.zhu_btn_caiji.setObjectName("zhu_btn_caiji")

        self.zhu_xiangji = QtWidgets.QLabel(MainWindow)

        self.zhu_shijian = QtWidgets.QLabel(self.centralwidget)
        self.zhu_shijian.setGeometry(QtCore.QRect(380, 90, 331, 51))
        font = QtGui.QFont()
        font.setFamily("方正姚体")
        font.setPointSize(16)
        self.zhu_shijian.setFont(font)
        self.zhu_shijian.setObjectName("zhu_shijian")

        self.zhu_btn_xiangji = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_xiangji.setGeometry(QtCore.QRect(470, 380, 171, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_xiangji.setFont(font)
        self.zhu_btn_xiangji.setStyleSheet("image: url(:/新前缀/打开相机.png);")
        self.zhu_btn_xiangji.setText("")
        self.zhu_btn_xiangji.setObjectName("zhu_btn_xiangji")
        self.zhu_btn_gengxin = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_gengxin.setGeometry(QtCore.QRect(180, 540, 161, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_gengxin.setFont(font)
        self.zhu_btn_gengxin.setStyleSheet("image: url(:/新前缀/信息更新.png);")
        self.zhu_btn_gengxin.setText("")
        self.zhu_btn_gengxin.setObjectName("zhu_btn_gengxin")
    
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        
        self.zhu_btn_chaxun = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_chaxun.setGeometry(QtCore.QRect(470, 220, 171, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_chaxun.setFont(font)
        self.zhu_btn_chaxun.setStyleSheet("image: url(:/新前缀/查询.png);")
        self.zhu_btn_chaxun.setText("")
        self.zhu_btn_chaxun.setObjectName("zhu_btn_chaxun")
        self.zhu_btn_tuichu = QtWidgets.QPushButton(self.centralwidget)
        self.zhu_btn_tuichu.setGeometry(QtCore.QRect(530, 540, 121, 81))
        font = QtGui.QFont()
        font.setFamily("Agency FB")
        font.setPointSize(16)
        self.zhu_btn_tuichu.setFont(font)
        self.zhu_btn_tuichu.setStyleSheet("image: url(:/新前缀/退出.png);")
        self.zhu_btn_tuichu.setText("")
        self.zhu_btn_tuichu.setObjectName("zhu_btn_tuichu")
        self.zhu_zhuangtailan = QtWidgets.QTextBrowser(self.centralwidget)
        self.zhu_zhuangtailan.setGeometry(QtCore.QRect(0, 620, 711, 31))
        self.zhu_zhuangtailan.setObjectName("zhu_zhuangtailan")
        MainWindow.setCentralWidget(self.centralwidget)
        self.actiondakai = QtWidgets.QAction(MainWindow)
        self.actiondakai.setObjectName("actiondakai")
        self.actionbaocun = QtWidgets.QAction(MainWindow)
        self.actionbaocun.setObjectName("actionbaocun")

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        self._translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(self._translate("MainWindow", "学生打卡系统"))
        self.biaoti.setText(self._translate("MainWindow", "人脸识别学生打卡系统"))
        self.zhu_shijian.setText(self._translate("MainWindow", "周二 4月18日 20:17:35 2021"))
        self.zhu_zhuangtailan.setHtml("状态栏：提示信息")
        self.actiondakai.setText(self._translate("MainWindow", "dakai "))
        self.actionbaocun.setText(self._translate("MainWindow", "baocun"))
        self.new_set()

    def new_set(self):
        
        # 设置按钮的槽函数
        self.zhu_btn_caiji.clicked.connect(self.caiji)
        self.zhu_btn_gengxin.clicked.connect(self.gengxin)
        self.zhu_btn_kaoqin.clicked.connect(self.kaoqin)
        self.zhu_btn_chaxun.clicked.connect(self.chaxun)
        self.zhu_btn_xiangji.clicked.connect(self.xiangji)
        self.zhu_btn_tuichu.clicked.connect(quit)

        # 给按键设置提示
        self.zhu_btn_caiji.setToolTip("信息采集系统")
        self.zhu_btn_gengxin.setToolTip("信息更新系统")
        self.zhu_btn_kaoqin.setToolTip("考勤系统")
        self.zhu_btn_chaxun.setToolTip("考勤信息查询系统")
        self.zhu_btn_xiangji.setToolTip("打开相机")
        self.zhu_btn_tuichu.setToolTip("退出系统")
        self.xiangji_zhuangtai = 1 # 定义一个变量，用来打开和关闭相机
     
    def caiji(self):
        self.zhu_zhuangtailan.setHtml("信息采集正在打开，请稍等")

        # 创建一个子窗口QDialog
        dialog= QDialog()
        # 创建一个窗口类
        main_window = xinxi_caiji() 
        # 窗口类的显示
        main_window.setupUi(dialog)
        dialog.setWindowModality(Qt.ApplicationModal)
        dialog.show()
        self.zhu_zhuangtailan.setHtml("信息采集已为您打开")
        # 等待窗口做出反应
        dialog.exec()
        self.zhu_zhuangtailan.setHtml("状态栏：提示信息")



    def gengxin(self):
        self.zhu_zhuangtailan.setHtml("更新信息正在打开，请稍等")
        # 创建一个子窗口QDialog
        dialog=QDialog()
        # 创建一个窗口类
        main_window = gengxin_xinxi() 
        dialog.setWindowModality(Qt.ApplicationModal)
        # 窗口类的显示
        main_window.setupUi(dialog)
        dialog.show()
        self.zhu_zhuangtailan.setHtml("更新信息已为您打开")
        # 等待窗口做出反应
        dialog.exec()
        self.zhu_zhuangtailan.setHtml("状态栏：提示信息")
    
    def kaoqin(self):
        self.zhu_zhuangtailan.setHtml("考勤系统正在打开，请稍等")
       
        # 创建一个子窗口QDialog
        dialog=QDialog()
        # 创建一个窗口类
        main_window = kaoqin() 
        # 窗口类的显示
        main_window.setupUi(dialog)
        dialog.setWindowModality(Qt.ApplicationModal)
        dialog.show()
        self.zhu_zhuangtailan.setHtml("考勤系统已为您打开")
        # 等待窗口做出反应
        dialog.exec()
        self.zhu_zhuangtailan.setHtml("状态栏：提示信息")
    
    def chaxun(self):
        self.zhu_zhuangtailan.setHtml("查询考勤信息系统正在打开，请稍等")
        # 创建一个子窗口QDialog
        dialog=QDialog()
        # 创建一个窗口类
        main_window = shuju_xianshi() 
        dialog.setWindowModality(Qt.ApplicationModal)
        # 窗口类的显示
        main_window.setupUi(dialog)
        dialog.show()
        self.zhu_zhuangtailan.setHtml("查询考勤信息系统已为您打开")
        # 等待窗口做出反应
        dialog.exec()
        self.zhu_zhuangtailan.setHtml("状态栏：提示信息")
    
    def xiangji(self, MainWindow):
        if self.xiangji_zhuangtai == 1:

            
            self.zhu_xiangji.setGeometry(QtCore.QRect(50, 150, 380, 350))
            self.zhu_xiangji.setObjectName("zhu_xiangji")

            self.zhu_zhuangtailan.setHtml("相机正在打开，请稍等")
            # 打开相机
            self.capture = cv2.VideoCapture(0)  
            self.zhu_zhuangtailan.setHtml("相机已经打开")
            self.xiangji_zhuangtai=2
            ret, self.frame = self.capture.read()
            self.frame = cv2.resize(self.frame,(400,350))
            self.frame=cv2.cvtColor(self.frame,cv2.COLOR_BGR2RGB)
            self.Qframe=QImage(self.frame.data,self.frame.shape[1],self.frame.shape[0],self.frame.shape[1]*3,QImage.Format_RGB888)
            self.zhu_xiangji.setPixmap(QPixmap.fromImage(self.Qframe))
              
        else:
            self.xiangji_zhuangtai = 1 
            self.capture.release()
            self.zhu_xiangji.setGeometry(QtCore.QRect(800, 500, 801, 501))
            self.zhu_zhuangtailan.setHtml("相机已经关闭")


